package com.shawn.model.vo;

import com.shawn.commons.utils.RC;
import com.shawn.model.entity.UserInfo;
import com.shawn.model.mongo.Comment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.text.SimpleDateFormat;

/**
 * 评论点赞喜欢的统一响应vo
 *
 * @author lenovo
 * @date 2022/11/02
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MessageVo {
    private String id;
    private String avatar;
    private String nickname;
    private String createDate;

    public static MessageVo init(Comment comment, UserInfo userInfo){
        MessageVo vo = new MessageVo();
        BeanUtils.copyProperties(userInfo,vo);
        vo.setId(comment.getId().toHexString());
        Long created = comment.getCreated();
        SimpleDateFormat format = new SimpleDateFormat(RC.ANNOUNCEMENT_DATE_FORMAT);
        vo.setCreateDate(format.format(created));
        return vo;
    }
}
